package com.linshuo.employee.service.impl;

import com.linshuo.employee.entity.FamilyMember;
import com.linshuo.employee.repository.FamilyMemberRepository;
import com.linshuo.employee.service.FamilyMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class FamilyMemberServiceImpl implements FamilyMemberService {
    @Autowired
    private FamilyMemberRepository familyMemberRepository;

    @Override
    public FamilyMember saveFamilyMember(FamilyMember familyMember) {
        return familyMemberRepository.save(familyMember);
    }

    @Override
    public FamilyMember updateFamilyMember(FamilyMember familyMember) {
        return familyMemberRepository.save(familyMember);
    }

    @Override
    public void deleteFamilyMember(Long id) {
        familyMemberRepository.deleteById(id);
    }

    @Override
    public FamilyMember getFamilyMemberById(Long id) {
        Optional<FamilyMember> familyMember = familyMemberRepository.findById(id);
        return familyMember.orElse(null);
    }

    @Override
    public List<FamilyMember> getAllFamilyMembers() {
        return familyMemberRepository.findAll();
    }
} 